package com.zjl.springbatch.job.partitioner;

import com.zjl.springbatch.util.OutColour;
import org.springframework.batch.core.partition.support.Partitioner;
import org.springframework.batch.item.ExecutionContext;

import java.util.HashMap;
import java.util.Map;
//分区器设置，将需要的 from和 to range 设置到步奏中
public class DBToDBPartitioner implements Partitioner {
    @Override
    public Map<String, ExecutionContext> partition(int gridSize) {
        Map<String, ExecutionContext> map = new HashMap<>();
        int from = 1;
        int to = 10000;
        int range = 10000;
        String text = "--DBToDBPartitioner----第%s分区-----开始：%s-----结束：%s-----数量：%s-----";
        for (int i = 0; i < gridSize; i++) {
            OutColour.out.printlnGreen(String.format(text,i,from,to,(to-from+1)));
            ExecutionContext ex = new ExecutionContext();
            ex.putInt("from",from);
            ex.putInt("to",to);
            ex.putInt("range",range);
            to += range;
            from += range;
            map.put("partitioner_" + i,ex);
        }

        return map;
    }
}
